<?php


namespace app\admin\controller\jizhan;

use app\admin\model\HtnsActivity;
use app\admin\model\HtnsActivityProduct;
use app\admin\model\HtnsActivityProductCate;
use app\admin\model\HtnsProduct;
use app\admin\traits\Curd;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use jianyan\excel\Excel;
use think\App;

/**
 * Class Admin
 * @package app\admin\controller\system
 * @ControllerAnnotation(title="基站-活动商品分类")
 */
class ActivityProductCate extends AdminController
{

    use Curd;


    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new HtnsActivityProductCate();
    }

    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->count();
            $list  = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select()->toArray();
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }

    // 分类列表
    /**
     * @NodeAnotation(title="分类列表")
     */
    public function list()
    {
        $ret['code'] = 1;
        $ret['msg']  = '获取成功';
        $ret['data'] = [];

        $where[]     = ['status', '=', 1];
        $htnsActivityProductCate = HtnsActivityProductCate::where($where)->order('id desc')->select()->toArray();
        if ($htnsActivityProductCate) {
            foreach ($htnsActivityProductCate as $v) {
                $retv          = [
                    'id'         => $v['id'],
                    'name' => $v['name'],
                    'cate_info' => $v['id'] . '-' . $v['name'],
                ];
                $ret['data'][] = $retv;
            }
        }
        return json($ret);
    }

}